﻿[assembly: System.Web.UI.TagPrefix("GSC.WebControls", "GSC")]
namespace GSC.WebControls
{ 
    using System;
    using System.Collections.Generic;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.Design.WebControls;
    using System.Drawing.Design;
    using System.Drawing;
    using System.Web.UI.Design;
    using System.ComponentModel;
    using ComponentModel.Design;
    using System.Resources;
    using System.Security.Permissions;
    /// <summary>
    /// 异步加载等待控件。
    /// </summary>
    /// <remarks>异步加载等待控件。</remarks>
    [
    //ToolboxBitmap(typeof(System.Web.UI.WebControls.Image)),
    ToolboxItemFilter("GSC.WebControls", ToolboxItemFilterType.Custom),
    SRDescription("AsyncListLoadingWaitControl", typeof(Properties.Resources)),
    ToolboxData("<{0}:AsyncListLoadingWaitControl runat=server></{0}:AsyncListLoadingWaitControl>"),
    Designer(typeof(AsyncListLoadingWaitControlDesigner))
    ]
    [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
    [AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)]
    public class AsyncListLoadingWaitControl : UpdatePanel, IResourceManager
    {
        #region IResourceManager
        ResourceManager _rm = null;
        /// <summary>
        /// 获取资源对象。
        /// </summary>
        /// <remarks>获取资源对象。</remarks>
        /// <value>System.Resources.ResourceManager</value>
        [Browsable(false)]
        public ResourceManager ResourceManager
        {
            get
            {
                if (_rm == null) _rm = new ResourceManager(typeof(AsyncListLoadingWaitControl));
                return _rm;
            }
        }
        /// <summary>
        /// 获取资源字符。
        /// </summary>
        /// <remarks>获取资源字符。</remarks>
        /// <param name="key"></param>
        /// <returns>string</returns>
        public string GetString(string key)
        {
            return this.ResourceManager.GetString(key);
        }
        #endregion
        /// <summary>
        /// 
        /// </summary>
        /// <param name="writer"></param>
        protected override void Render(HtmlTextWriter writer)
        {
            writer.AddStyleAttribute(HtmlTextWriterStyle.Display, "none");
            base.Render(writer);
        }
        LoadingWaitControl _loadingWaitControl;
        List<Control> _registerControlLists = new List<Control>();
        List<string> _asyncLoadings = new List<string>();
        /// <summary>
        /// 注册异步加载等待控件事件。
        /// </summary>
        /// <remarks>注册异步加载等待控件事件。</remarks>
        [Browsable(true)]
        [Category("Behavior")]
        //[SRDescription("AsyncListLoadingWaitControl_Register", typeof(Properties.Resources))]
        public event EventHandler Register
        {
            add
            {
                Events.AddHandler(_registerObject, value);
            }
            remove
            {
                Events.RemoveHandler(_registerObject, value);
            }
        }
        /// <summary>
        /// 
        /// </summary>
        private static readonly object _registerObject = new object();
        /// <summary>
        /// 获取异步加载等待控件列表。
        /// </summary>
        /// <remarks>获取异步加载等待控件列表。</remarks>
        /// <value>System.Collections.Generic.List&lt;string&gt;</value>
        [Browsable(false)]
        public List<string> AsyncLoadings
        {
            get
            {
                return this._asyncLoadings;
            }
        }
        /// <summary>
        /// 获取或设置遮掩层渐现增加幅度。
        /// </summary>
        /// <remarks>获取或设置遮掩层渐现增加幅度。</remarks>
        /// <value>double</value>
        [DefaultValue(0.01)]
        [Bindable(true)]
        [Browsable(true)]
        [Category("Behavior")]
       // [SRDescription("AsyncListLoadingWaitControl_Starts", typeof(Properties.Resources))]
        public double Starts
        {
            get
            {
                object o = this.ViewState["Starts"];
                if (o == null) return 0.01;
                return (double)o;
            }
            set
            {
                this.ViewState["Starts"] = value;
            }
        }

        /// <summary>
        /// 获取或设置遮掩层背景原色。
        /// </summary>
        /// <remarks>获取或设置遮掩层背景原色。</remarks>
        /// <value>System.Drawing.Color</value>
        [DefaultValue(typeof(Color), "Black")]
        [Bindable(true)]
        [Browsable(true)]
        [Category("Appearance")]
        //[SRDescription("AsyncListLoadingWaitControl_FillWindowColor", typeof(Properties.Resources))]
        public Color FillWindowColor
        {
            get
            {
                object o = this.ViewState["FillWindowColor"];
                if (o == null) return Color.Black;
                return (Color)o;
            }
            set
            {
                this.ViewState["FillWindowColor"] = value;
            }
        }

        /// <summary>
        /// 获取或设置加载视图图标。
        /// </summary>
        /// <remarks>获取或设置加载视图图标。</remarks>
        /// <value>string</value>
        [DefaultValue("")]
        [Editor(typeof(ImageUrlEditor), typeof(UITypeEditor))]
        [Bindable(true)]
        [Browsable(true)]
        [Category("Appearance")]
       // [SRDescription("AsyncListLoadingWaitControl_LoadingImage", typeof(Properties.Resources))]
        public string LoadingImage
        {
            get
            {
                object o = this.ViewState["LoadingImage"];
                if (o == null) return string.Empty;
                return (string)o;
            }
            set
            {
                this.ViewState["LoadingImage"] = value;
            }
        }

        /// <summary>
        /// 获取或设置加载提示内容。
        /// </summary>
        /// <remarks>获取或设置加载提示内容。</remarks>
        /// <value>string</value>
        [Editor("System.ComponentModel.Design.MultilineStringEditor,System.Design", typeof(UITypeEditor))]
        [DefaultValue("")]
        [Bindable(true)]
        [Browsable(true)]
        [Category("Appearance")]
        //[SRDescription("AsyncListLoadingWaitControl_LoadingText", typeof(Properties.Resources))]
        [Localizable(true)]
        public string LoadingText
        {
            get
            {
                object o = this.ViewState["LoadingText"];
                if (o == null) return string.Empty;
                return (string)o;
            }
            set
            {
                this.ViewState["LoadingText"] = value;
            }
        }

        /// <summary>
        /// 获取或设置遮掩层透明度。
        /// </summary>
        /// <remarks>获取或设置遮掩层透明度。</remarks>
        /// <value>double</value>
        [DefaultValue(0.6)]
        [Bindable(true)]
        [Browsable(true)]
        [Category("Behavior")]
        //[SRDescription("AsyncListLoadingWaitControl_Opacity", typeof(Properties.Resources))]
        public double Opacity
        {
            get
            {
                object o = this.ViewState["Opacity"];
                if (o == null) return 0.6;
                return (double)o;
            }
            set
            {
                this.ViewState["Opacity"] = value;
            }
        }

        /// <summary>
        /// 获取或设置遮掩层渐变显示速度。
        /// </summary>
        /// <remarks>获取或设置遮掩层渐变显示速度。</remarks>
        /// <value>short</value>
        [DefaultValue(50)]
        [Bindable(true)]
        [Browsable(true)]
        [Category("Behavior")]
        //[SRDescription("AsyncListLoadingWaitControl_Speed", typeof(Properties.Resources))]
        public Int16 Speed
        {
            get
            {
                object o = this.ViewState["Speed"];
                if (o == null) return 50;
                return (Int16)o;
            }
            set
            {
                if (value <= 50) value = 50;
                this.ViewState["Speed"] = value;
            }
        }
        /// <summary>
        /// 获取注册控件列表集合。
        /// </summary>
        /// <remarks>获取注册控件列表集合。</remarks>
        /// <value>System.Collections.Generic.List&lt;System.Web.UI.Control&gt;</value>
        [Browsable(false)]
        public List<Control> RegisterControlLists
        {
            get
            {
                return _registerControlLists;
            }
        }
        /// <summary>
        /// 获取或设置遮掩层渐退减少幅度。
        /// </summary>
        /// <remarks>获取或设置遮掩层渐退减少幅度。</remarks>
        /// <value>double</value>
        [DefaultValue(0)]
        [Bindable(true)]
        [Browsable(true)]
        [Category("Behavior")]
        //[SRDescription("AsyncListLoadingWaitControl_Degenerating", typeof(Properties.Resources))]
        public double Degenerating
        {
            get
            {
                object o = this.ViewState["Degenerating"];
                if (o == null) return 0;
                return (Int16)o;
            }
            set
            {
                if (value < 0) value = 0;
                this.ViewState["Degenerating"] = value;
            }
        }
        /// <summary>
        /// 基础结构。基于存储在视图状态中的值创建用来呈现复合数据绑定控件的控件层次结构。 （重写 Control.CreateChildControls()。）
        /// </summary>
        /// <remarks>基础结构。基于存储在视图状态中的值创建用来呈现复合数据绑定控件的控件层次结构。 （重写 Control.CreateChildControls()。）</remarks>
        protected override void CreateChildControls()
        {
            base.CreateChildControls();
            base.ContentTemplateContainer.Controls.Clear();
            this._loadingWaitControl = new LoadingWaitControl(this);
            this._loadingWaitControl.ID += "LoadingWaitControl";
            base.ContentTemplateContainer.Controls.Add(this._loadingWaitControl);
            base.ClearChildViewState();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="c"></param>
        void AddNext(Control c)
        {
            if (c is IAsyncControlIDsExtender)
            {
                foreach (string item in ((IAsyncControlIDsExtender)c).ControlIDs)
                {
                    this.Add(item);
                }
            }
            else if (c is Table)
            {
                foreach (TableRow item in ((Table)c).Rows)
                {
                    foreach (TableCell citem in item.Cells)
                    {
                        foreach (Control ccitem in citem.Controls)
                        {
                            if (ccitem is LinkButton || ccitem is ImageButton || ccitem is Button)
                            {
                                this.Add(ccitem.ClientID);
                            }
                            else if (ccitem is DropDownList)
                            {
                                if (((DropDownList)ccitem).AutoPostBack)
                                {
                                    this.Add(ccitem.ClientID);
                                }
                            }
                            else if (ccitem is CheckBox)
                            {
                                if (((CheckBox)ccitem).AutoPostBack)
                                {
                                    this.Add(ccitem.ClientID);
                                }
                            }
                            else
                            {
                                this.AddNext(ccitem);
                            }
                        }
                    }
                }
            }
            else if (c is TableRow)
            {
                foreach (TableCell citem in ((TableRow)c).Cells)
                {
                    foreach (Control ccitem in citem.Controls)
                    {
                        if (ccitem is LinkButton || ccitem is ImageButton || ccitem is Button)
                        {
                            this.Add(ccitem.ClientID);
                        }
                        else if (ccitem is DropDownList)
                        {
                            if (((DropDownList)ccitem).AutoPostBack)
                            {
                                this.Add(ccitem.ClientID);
                            }
                        }
                        else if (ccitem is CheckBox)
                        {
                            if (((CheckBox)ccitem).AutoPostBack)
                            {
                                this.Add(ccitem.ClientID);
                            }
                        }
                        else
                        {
                            this.AddNext(ccitem);
                        }
                    }
                }
            }
            else if (c is HtmlTable)
            {
                foreach (HtmlTableRow item in ((HtmlTable)c).Rows)
                {
                    foreach (HtmlTableCell citem in item.Cells)
                    {
                        foreach (Control ccitem in citem.Controls)
                        {
                            if (ccitem is LinkButton || ccitem is ImageButton || ccitem is Button)
                            {
                                this.Add(ccitem.ClientID);
                            }
                            else if (ccitem is DropDownList)
                            {
                                if (((DropDownList)ccitem).AutoPostBack)
                                {
                                    this.Add(ccitem.ClientID);
                                }
                            }
                            else if (ccitem is CheckBox)
                            {
                                if (((CheckBox)ccitem).AutoPostBack)
                                {
                                    this.Add(ccitem.ClientID);
                                }
                            }
                            else
                            {
                                this.AddNext(ccitem);
                            }
                        }
                    }
                }
            }
            else if (c is HtmlTableRow)
            {
                foreach (HtmlTableCell citem in ((HtmlTableRow)c).Cells)
                {
                    foreach (Control ccitem in citem.Controls)
                    {
                        if (ccitem is LinkButton || ccitem is ImageButton || ccitem is Button)
                        {
                            this.Add(ccitem.ClientID);
                        }
                        else if (ccitem is DropDownList)
                        {
                            if (((DropDownList)ccitem).AutoPostBack)
                            {
                                this.Add(ccitem.ClientID);
                            }
                        }
                        else if (ccitem is CheckBox)
                        {
                            if (((CheckBox)ccitem).AutoPostBack)
                            {
                                this.Add(ccitem.ClientID);
                            }
                        }
                        else
                        {
                            this.AddNext(ccitem);
                        }
                    }
                }
            }
            else if (c is ListView)
            {
                foreach (ListViewDataItem item in ((ListView)c).Items)
                {
                    foreach (Control citem in item.Controls)
                    {
                        if (citem is HtmlTableCell)
                        {
                            foreach (Control ccitem in citem.Controls)
                            {
                                if (ccitem is LinkButton || ccitem is ImageButton || ccitem is Button)
                                {
                                    this.Add(ccitem.ClientID);
                                }
                                else if (ccitem is DropDownList)
                                {
                                    if (((DropDownList)ccitem).AutoPostBack)
                                    {
                                        this.Add(ccitem.ClientID);
                                    }
                                }
                                else if (ccitem is CheckBox)
                                {
                                    if (((CheckBox)ccitem).AutoPostBack)
                                    {
                                        this.Add(ccitem.ClientID);
                                    }
                                }
                                else
                                {
                                    this.AddNext(ccitem);
                                }
                            }
                        }
                    }
                }
            }
            else if (c is FormView)
            {
                foreach (TableCell citem in ((FormView)c).Row.Cells)
                {
                    foreach (Control ccitem in citem.Controls)
                    {
                        if (ccitem is LinkButton || ccitem is ImageButton || ccitem is Button)
                        {
                            this.Add(ccitem.ClientID);
                        }
                        else if (ccitem is DropDownList)
                        {
                            if (((DropDownList)ccitem).AutoPostBack)
                            {
                                this.Add(ccitem.ClientID);
                            }
                        }
                        else if (ccitem is CheckBox)
                        {
                            if (((CheckBox)ccitem).AutoPostBack)
                            {
                                this.Add(ccitem.ClientID);
                            }
                        }
                        else
                        {
                            this.AddNext(ccitem);
                        }
                    }
                }
            }
            else if (c is DetailsView)
            {
                foreach (DetailsViewRow item in ((DetailsView)c).Rows)
                {
                    foreach (TableCell citem in item.Cells)
                    {
                        foreach (Control ccitem in citem.Controls)
                        {
                            if (ccitem is LinkButton || ccitem is ImageButton || ccitem is Button)
                            {
                                this.Add(ccitem.ClientID);
                            }
                            else if (ccitem is DropDownList)
                            {
                                if (((DropDownList)ccitem).AutoPostBack)
                                {
                                    this.Add(ccitem.ClientID);
                                }
                            }
                            else if (ccitem is CheckBox)
                            {
                                if (((CheckBox)ccitem).AutoPostBack)
                                {
                                    this.Add(ccitem.ClientID);
                                }
                            }
                            else
                            {
                                this.AddNext(ccitem);
                            }
                        }
                    }
                }
            }
            else if (c is DataList)
            {
                foreach (DataListItem item in ((DataList)c).Items)
                {
                    foreach (Control citem in item.Controls)
                    {
                        if (citem is LinkButton || citem is ImageButton || citem is Button)
                        {
                            this.Add(citem.ClientID);
                        }
                        else if (citem is DropDownList)
                        {
                            if (((DropDownList)citem).AutoPostBack)
                            {
                                this.Add(citem.ClientID);
                            }
                        }
                        else if (citem is CheckBox)
                        {
                            if (((CheckBox)citem).AutoPostBack)
                            {
                                this.Add(citem.ClientID);
                            }
                        }
                        else
                        {
                            this.AddNext(citem);
                        }
                    }
                }
            }
            else if (c is GridView)
            {
                GridView gridView = (GridView)c;
                foreach (GridViewRow item in gridView.Rows)
                {
                    foreach (TableCell citem in item.Cells)
                    {
                        foreach (Control ccitem in citem.Controls)
                        {
                            if (ccitem is LinkButton || ccitem is ImageButton || ccitem is Button)
                            {
                                this.Add(ccitem.ClientID);
                            }
                            else if (ccitem is DropDownList)
                            {
                                if (((DropDownList)ccitem).AutoPostBack)
                                {
                                    this.Add(ccitem.ClientID);
                                }
                            }
                            else if (ccitem is CheckBox)
                            {
                                if (((CheckBox)ccitem).AutoPostBack)
                                {
                                    this.Add(ccitem.ClientID);
                                }
                            }
                            else
                            {
                                this.AddNext(ccitem);
                            }
                        }
                    }
                }
                if (gridView.BottomPagerRow != null)
                {
                    foreach (TableCell citem in gridView.BottomPagerRow.Cells)
                    {
                        foreach (Control ccitem in citem.Controls)
                        {
                            if (ccitem is LinkButton || ccitem is ImageButton || ccitem is Button)
                            {
                                this.Add(ccitem.ClientID);
                            }
                            else if (ccitem is DropDownList)
                            {
                                if (((DropDownList)ccitem).AutoPostBack)
                                {
                                    this.Add(ccitem.ClientID);
                                }
                            }
                            else if (ccitem is CheckBox)
                            {
                                if (((CheckBox)ccitem).AutoPostBack)
                                {
                                    this.Add(ccitem.ClientID);
                                }
                            }
                            else
                            {
                                this.AddNext(ccitem);
                            }
                        }
                    }
                }
                if (gridView.TopPagerRow != null)
                {
                    foreach (TableCell citem in gridView.TopPagerRow.Cells)
                    {
                        foreach (Control ccitem in citem.Controls)
                        {
                            if (ccitem is LinkButton || ccitem is ImageButton || ccitem is Button)
                            {
                                this.Add(ccitem.ClientID);
                            }
                            else if (ccitem is DropDownList)
                            {
                                if (((DropDownList)ccitem).AutoPostBack)
                                {
                                    this.Add(ccitem.ClientID);
                                }
                            }
                            else if (ccitem is CheckBox)
                            {
                                if (((CheckBox)ccitem).AutoPostBack)
                                {
                                    this.Add(ccitem.ClientID);
                                }
                            }
                            else
                            {
                                this.AddNext(ccitem);
                            }
                        }
                    }
                }
                if (gridView.HeaderRow != null)
                {
                    foreach (TableCell citem in gridView.HeaderRow.Cells)
                    {
                        foreach (Control ccitem in citem.Controls)
                        {
                            if (ccitem is LinkButton || ccitem is ImageButton || ccitem is Button)
                            {
                                this.Add(ccitem.ClientID);
                            }
                            else if (ccitem is DropDownList)
                            {
                                if (((DropDownList)ccitem).AutoPostBack)
                                {
                                    this.Add(ccitem.ClientID);
                                }
                            }
                            else if (ccitem is CheckBox)
                            {
                                if (((CheckBox)ccitem).AutoPostBack)
                                {
                                    this.Add(ccitem.ClientID);
                                }
                            }
                            else
                            {
                                this.AddNext(ccitem);
                            }
                        }
                    }
                }
            }
            else if (c is LinkButton || c is ImageButton || c is Button)
            {
                this.Add(c.ClientID);
            }
            else if (c is DropDownList)
            {
                if (((DropDownList)c).AutoPostBack)
                {
                    this.Add(c.ClientID);
                }
            }
            else if (c is CheckBox)
            {
                if (((CheckBox)c).AutoPostBack)
                {
                    this.Add(c.ClientID);
                }
            }
            else
            {
                foreach (Control ccitem in c.Controls)
                {
                    if (ccitem is LinkButton || ccitem is ImageButton || ccitem is Button)
                    {
                        this.Add(ccitem.ClientID);
                    }
                    else if (ccitem is DropDownList)
                    {
                        if (((DropDownList)ccitem).AutoPostBack)
                        {
                            this.Add(ccitem.ClientID);
                        }
                    }
                    else if (ccitem is CheckBox)
                    {
                        if (((CheckBox)ccitem).AutoPostBack)
                        {
                            this.Add(ccitem.ClientID);
                        }
                    }
                    else
                    {
                        this.AddNext(ccitem);
                    }
                }
            }
        }
        /// <summary>
        /// </summary>
        /// <param name="clientID"></param>
        void Add(string clientID)
        {
            if (this._asyncLoadings.Contains(clientID)) return;
            this._asyncLoadings.Add(clientID);
        }
        /// <summary>
        /// 如果已经 RegisterDataItem 注册了控件侧退出不重复注册。
        /// </summary>
        bool _isUpdateComplete = false;
        /// <summary>
        /// 使用控件本身调用更新完成。
        /// </summary>
        /// <remarks>使用控件本身调用更新完成。</remarks>
        public void UpdateComplete()
        {
            if (_isUpdateComplete) return;
            _isUpdateComplete = true;
            this.EnsureChildControls();
            if (ScriptManager.GetCurrent(this.Page).IsInAsyncPostBack)
            {
                ScriptManager.GetCurrent(this.Page).RegisterDataItem(this._loadingWaitControl, "__GSC__AsyncListLoadingWaitControlUpdateComplete");
                if (base.UpdateMode == UpdatePanelUpdateMode.Conditional)
                {
                    base.Update();
                }
            }
        }
        /// <summary>
        /// 指定回调控件调用更新完成。
        /// </summary>
        /// <remarks>指定回调控件调用更新完成。</remarks>
        /// <param name="control">设置回调注册控件。</param>
        public void UpdateComplete(Control control)
        {
            if (_isUpdateComplete) return;
            _isUpdateComplete = true;
            this.EnsureChildControls();
            if (ScriptManager.GetCurrent(this.Page).IsInAsyncPostBack)
            {
                ScriptManager.GetCurrent(this.Page).RegisterDataItem(control, "__GSC__AsyncListLoadingWaitControlUpdateComplete");
                if (base.UpdateMode == UpdatePanelUpdateMode.Conditional)
                {
                    base.Update();
                }
            }
        }
        /// <summary>
        /// 使用控件本身调用更新完成。
        /// </summary>
        /// <remarks>使用控件本身调用更新完成。</remarks>
        /// <param name="returnContent">设置回调的数组字符内容，使用{|}作为数组分隔符。</param>
        public void UpdateComplete(string[] returnContent)
        {
            if (_isUpdateComplete) return;
            _isUpdateComplete = true;
            this.EnsureChildControls();
            if (ScriptManager.GetCurrent(this.Page).IsInAsyncPostBack)
            {
                string s = string.Empty;
                foreach (string item in returnContent)
                {
                    if (s == string.Empty)
                    {
                        s += item;
                    }
                    else
                    {
                        s += ("|" + item);
                    }
                }
                ScriptManager.GetCurrent(this.Page).RegisterDataItem(this._loadingWaitControl, "__GSC__AsyncListLoadingWaitControlUpdateComplete|" + s);
                if (base.UpdateMode == UpdatePanelUpdateMode.Conditional)
                {
                    base.Update();
                }
            }
        }
        /// <summary>
        /// 使用控件本身调用更新完成。
        /// </summary>
        /// <remarks>使用控件本身调用更新完成。</remarks>
        /// <param name="returnContent">设置回调的数组字符内容。</param>
        public void UpdateComplete(List<string> returnContent)
        {
            this.UpdateComplete(returnContent.ToArray());
        }
        /// <summary>
        /// 使用控件本身调用更新完成。
        /// </summary>
        /// <remarks>使用控件本身调用更新完成。</remarks>
        /// <param name="returnContent">设置回调的字符内容或数组字符内容以{|}为分隔符。</param>
        public void UpdateComplete(string returnContent)
        {
            if (_isUpdateComplete) return;
            _isUpdateComplete = true;
            this.EnsureChildControls();
            if (ScriptManager.GetCurrent(this.Page).IsInAsyncPostBack)
            {
                ScriptManager.GetCurrent(this.Page).RegisterDataItem(this._loadingWaitControl, "__GSC__AsyncListLoadingWaitControlUpdateComplete" + (returnContent.StartsWith("|") ? returnContent : ("|" + returnContent)));
                if (base.UpdateMode == UpdatePanelUpdateMode.Conditional)
                {
                    base.Update();
                }
            }
        }
        /// <summary>
        /// 指定回调控件调用更新完成。
        /// </summary>
        /// <remarks>指定回调控件调用更新完成。</remarks>
        /// <param name="control">设置回调注册控件。</param>
        /// <param name="returnContent">设置回调的数组字符内容，使用{|}作为数组分隔符。</param>
        public void UpdateComplete(Control control, string[] returnContent)
        {
            if (_isUpdateComplete) return;
            _isUpdateComplete = true;
            this.EnsureChildControls();
            if (ScriptManager.GetCurrent(this.Page).IsInAsyncPostBack)
            {
                string s = string.Empty;
                foreach (string item in returnContent)
                {
                    if (s == string.Empty)
                    {
                        s += item;
                    }
                    else
                    {
                        s += ("|" + item);
                    }
                }
                ScriptManager.GetCurrent(this.Page).RegisterDataItem(control, "__GSC__AsyncListLoadingWaitControlUpdateComplete|" + s);
                if (base.UpdateMode == UpdatePanelUpdateMode.Conditional)
                {
                    base.Update();
                }
            }
        }
        /// <summary>
        /// 指定回调控件调用更新完成。
        /// </summary>
        /// <remarks>指定回调控件调用更新完成。</remarks>
        /// <param name="control">设置回调注册控件。</param>
        /// <param name="returnContent">设置回调的数组字符内容。</param>
        public void UpdateComplete(Control control, List<string> returnContent)
        {
            this.UpdateComplete(control,returnContent.ToArray());
        }
        /// <summary>
        /// 指定回调控件调用更新完成。
        /// </summary>
        /// <remarks>指定回调控件调用更新完成。</remarks>
        /// <param name="control">设置回调注册控件。</param>
        /// <param name="returnContent">设置回调的字符内容或数组字符内容以{|}为分隔符。</param>
        public void UpdateComplete(Control control, string returnContent)
        {
            if (_isUpdateComplete) return;
            _isUpdateComplete = true;
            this.EnsureChildControls();
            if (ScriptManager.GetCurrent(this.Page).IsInAsyncPostBack)
            {
                ScriptManager.GetCurrent(this.Page).RegisterDataItem(control, "__GSC__AsyncListLoadingWaitControlUpdateComplete" + (returnContent.StartsWith("|") ? returnContent : ("|" + returnContent)));
                if (base.UpdateMode == UpdatePanelUpdateMode.Conditional)
                {
                    base.Update();
                }
            }
        }
        /// <summary>
        /// 卸载异步加载等待控件对象，卸载异步等待控件方法必须在 Register 事件中执行。
        /// </summary>
        /// <remarks>卸载异步加载等待控件对象，卸载异步等待控件方法必须在 Register 事件中执行。</remarks>
        /// <param name="control">设置要卸载的控件客户端ID。</param>
        /// <returns>bool</returns>
        public bool UninstallControl(string control)
        {
            return this._asyncLoadings.Remove(control);
        }
        /// <summary>
        /// 卸载异步加载等待控件对象，卸载异步等待控件方法必须在 Register 事件中执行。
        /// </summary>
        /// <remarks>卸载异步加载等待控件对象。</remarks>
        /// <param name="control">设置要卸载的控件对象。</param>
        public void UninstallControl(Control control)
        {
            this.RemoveNext(control);
        }
        /// <summary>
        /// </summary>
        /// <param name="c"></param>
        void RemoveNext(Control c)
        {
            if (c is IAsyncControlIDsExtender)
            {
                foreach (string item in ((IAsyncControlIDsExtender)c).ControlIDs)
                {
                    this._asyncLoadings.Remove(item);
                }
            }
            else if (c is Table)
            {
                foreach (TableRow item in ((Table)c).Rows)
                {
                    foreach (TableCell citem in item.Cells)
                    {
                        foreach (Control ccitem in citem.Controls)
                        {
                            if (ccitem is LinkButton || ccitem is ImageButton || ccitem is Button)
                            {
                                this._asyncLoadings.Remove(ccitem.ClientID);
                            }
                            else if (ccitem is DropDownList)
                            {
                                if (((DropDownList)ccitem).AutoPostBack)
                                {
                                    this._asyncLoadings.Remove(ccitem.ClientID);
                                }
                            }
                            else if (ccitem is CheckBox)
                            {
                                if (((CheckBox)ccitem).AutoPostBack)
                                {
                                    this._asyncLoadings.Remove(ccitem.ClientID);
                                }
                            }
                            else
                            {
                                this.RemoveNext(ccitem);
                            }
                        }
                    }
                }
            }
            else if (c is TableRow)
            {
                foreach (TableCell citem in ((TableRow)c).Cells)
                {
                    foreach (Control ccitem in citem.Controls)
                    {
                        if (ccitem is LinkButton || ccitem is ImageButton || ccitem is Button)
                        {
                            this._asyncLoadings.Remove(ccitem.ClientID);
                        }
                        else if (ccitem is DropDownList)
                        {
                            if (((DropDownList)ccitem).AutoPostBack)
                            {
                                this._asyncLoadings.Remove(ccitem.ClientID);
                            }
                        }
                        else if (ccitem is CheckBox)
                        {
                            if (((CheckBox)ccitem).AutoPostBack)
                            {
                                this._asyncLoadings.Remove(ccitem.ClientID);
                            }
                        }
                        else
                        {
                            this.RemoveNext(ccitem);
                        }
                    }
                }
            }
            else if (c is HtmlTable)
            {
                foreach (HtmlTableRow item in ((HtmlTable)c).Rows)
                {
                    foreach (HtmlTableCell citem in item.Cells)
                    {
                        foreach (Control ccitem in citem.Controls)
                        {
                            if (ccitem is LinkButton || ccitem is ImageButton || ccitem is Button)
                            {
                                this._asyncLoadings.Remove(ccitem.ClientID);
                            }
                            else if (ccitem is DropDownList)
                            {
                                if (((DropDownList)ccitem).AutoPostBack)
                                {
                                    this._asyncLoadings.Remove(ccitem.ClientID);
                                }
                            }
                            else if (ccitem is CheckBox)
                            {
                                if (((CheckBox)ccitem).AutoPostBack)
                                {
                                    this._asyncLoadings.Remove(ccitem.ClientID);
                                }
                            }
                            else
                            {
                                this.RemoveNext(ccitem);
                            }
                        }
                    }
                }
            }
            else if (c is HtmlTableRow)
            {
                foreach (HtmlTableCell citem in ((HtmlTableRow)c).Cells)
                {
                    foreach (Control ccitem in citem.Controls)
                    {
                        if (ccitem is LinkButton || ccitem is ImageButton || ccitem is Button)
                        {
                            this._asyncLoadings.Remove(ccitem.ClientID);
                        }
                        else if (ccitem is DropDownList)
                        {
                            if (((DropDownList)ccitem).AutoPostBack)
                            {
                                this._asyncLoadings.Remove(ccitem.ClientID);
                            }
                        }
                        else if (ccitem is CheckBox)
                        {
                            if (((CheckBox)ccitem).AutoPostBack)
                            {
                                this._asyncLoadings.Remove(ccitem.ClientID);
                            }
                        }
                        else
                        {
                            this.RemoveNext(ccitem);
                        }
                    }
                }
            }
            else if (c is ListView)
            {
                foreach (ListViewDataItem item in ((ListView)c).Items)
                {
                    foreach (Control citem in item.Controls)
                    {
                        if (citem is HtmlTableCell)
                        {
                            foreach (Control ccitem in citem.Controls)
                            {
                                if (ccitem is LinkButton || ccitem is ImageButton || ccitem is Button)
                                {
                                    this._asyncLoadings.Remove(ccitem.ClientID);
                                }
                                else if (ccitem is DropDownList)
                                {
                                    if (((DropDownList)ccitem).AutoPostBack)
                                    {
                                        this._asyncLoadings.Remove(ccitem.ClientID);
                                    }
                                }
                                else if (ccitem is CheckBox)
                                {
                                    if (((CheckBox)ccitem).AutoPostBack)
                                    {
                                        this._asyncLoadings.Remove(ccitem.ClientID);
                                    }
                                }
                                else
                                {
                                    this.RemoveNext(ccitem);
                                }
                            }
                        }
                    }
                }
            }
            else if (c is FormView)
            {
                foreach (TableCell citem in ((FormView)c).Row.Cells)
                {
                    foreach (Control ccitem in citem.Controls)
                    {
                        if (ccitem is LinkButton || ccitem is ImageButton || ccitem is Button)
                        {
                            this._asyncLoadings.Remove(ccitem.ClientID);
                        }
                        else if (ccitem is DropDownList)
                        {
                            if (((DropDownList)ccitem).AutoPostBack)
                            {
                                this._asyncLoadings.Remove(ccitem.ClientID);
                            }
                        }
                        else if (ccitem is CheckBox)
                        {
                            if (((CheckBox)ccitem).AutoPostBack)
                            {
                                this._asyncLoadings.Remove(ccitem.ClientID);
                            }
                        }
                        else
                        {
                            this.RemoveNext(ccitem);
                        }
                    }
                }
            }
            else if (c is DetailsView)
            {
                foreach (DetailsViewRow item in ((DetailsView)c).Rows)
                {
                    foreach (TableCell citem in item.Cells)
                    {
                        foreach (Control ccitem in citem.Controls)
                        {
                            if (ccitem is LinkButton || ccitem is ImageButton || ccitem is Button)
                            {
                                this._asyncLoadings.Remove(ccitem.ClientID);
                            }
                            else if (ccitem is DropDownList)
                            {
                                if (((DropDownList)ccitem).AutoPostBack)
                                {
                                    this._asyncLoadings.Remove(ccitem.ClientID);
                                }
                            }
                            else if (ccitem is CheckBox)
                            {
                                if (((CheckBox)ccitem).AutoPostBack)
                                {
                                    this._asyncLoadings.Remove(ccitem.ClientID);
                                }
                            }
                            else
                            {
                                this.RemoveNext(ccitem);
                            }
                        }
                    }
                }
            }
            else if (c is DataList)
            {
                foreach (DataListItem item in ((DataList)c).Items)
                {
                    foreach (Control citem in item.Controls)
                    {
                        if (citem is LinkButton || citem is ImageButton || citem is Button)
                        {
                            this._asyncLoadings.Remove(citem.ClientID);
                        }
                        else if (citem is DropDownList)
                        {
                            if (((DropDownList)citem).AutoPostBack)
                            {
                                this._asyncLoadings.Remove(citem.ClientID);
                            }
                        }
                        else if (citem is CheckBox)
                        {
                            if (((CheckBox)citem).AutoPostBack)
                            {
                                this._asyncLoadings.Remove(citem.ClientID);
                            }
                        }
                        else
                        {
                            this.RemoveNext(citem);
                        }
                    }
                }
            }
            else if (c is GridView)
            {
                GridView gridView = (GridView)c;
                foreach (GridViewRow item in gridView.Rows)
                {
                    foreach (TableCell citem in item.Cells)
                    {
                        foreach (Control ccitem in citem.Controls)
                        {
                            if (ccitem is LinkButton || ccitem is ImageButton || ccitem is Button)
                            {
                                this._asyncLoadings.Remove(ccitem.ClientID);
                            }
                            else if (ccitem is DropDownList)
                            {
                                if (((DropDownList)ccitem).AutoPostBack)
                                {
                                    this._asyncLoadings.Remove(ccitem.ClientID);
                                }
                            }
                            else if (ccitem is CheckBox)
                            {
                                if (((CheckBox)ccitem).AutoPostBack)
                                {
                                    this._asyncLoadings.Remove(ccitem.ClientID);
                                }
                            }
                            else
                            {
                                this.RemoveNext(ccitem);
                            }
                        }
                    }
                }
                if (gridView.BottomPagerRow != null)
                {
                    foreach (TableCell citem in gridView.BottomPagerRow.Cells)
                    {
                        foreach (Control ccitem in citem.Controls)
                        {
                            if (ccitem is LinkButton || ccitem is ImageButton || ccitem is Button)
                            {
                                this._asyncLoadings.Remove(ccitem.ClientID);
                            }
                            else if (ccitem is DropDownList)
                            {
                                if (((DropDownList)ccitem).AutoPostBack)
                                {
                                    this._asyncLoadings.Remove(ccitem.ClientID);
                                }
                            }
                            else if (ccitem is CheckBox)
                            {
                                if (((CheckBox)ccitem).AutoPostBack)
                                {
                                    this._asyncLoadings.Remove(ccitem.ClientID);
                                }
                            }
                            else
                            {
                                this.RemoveNext(ccitem);
                            }
                        }
                    }
                }
                if (gridView.TopPagerRow != null)
                {
                    foreach (TableCell citem in gridView.TopPagerRow.Cells)
                    {
                        foreach (Control ccitem in citem.Controls)
                        {
                            if (ccitem is LinkButton || ccitem is ImageButton || ccitem is Button)
                            {
                                this._asyncLoadings.Remove(ccitem.ClientID);
                            }
                            else if (ccitem is DropDownList)
                            {
                                if (((DropDownList)ccitem).AutoPostBack)
                                {
                                    this._asyncLoadings.Remove(ccitem.ClientID);
                                }
                            }
                            else if (ccitem is CheckBox)
                            {
                                if (((CheckBox)ccitem).AutoPostBack)
                                {
                                    this._asyncLoadings.Remove(ccitem.ClientID);
                                }
                            }
                            else
                            {
                                this.RemoveNext(ccitem);
                            }
                        }
                    }
                }
                if (gridView.HeaderRow != null)
                {
                    foreach (TableCell citem in gridView.HeaderRow.Cells)
                    {
                        foreach (Control ccitem in citem.Controls)
                        {
                            if (ccitem is LinkButton || ccitem is ImageButton || ccitem is Button)
                            {
                                this._asyncLoadings.Remove(ccitem.ClientID);
                            }
                            else if (ccitem is DropDownList)
                            {
                                if (((DropDownList)ccitem).AutoPostBack)
                                {
                                    this._asyncLoadings.Remove(ccitem.ClientID);
                                }
                            }
                            else if (ccitem is CheckBox)
                            {
                                if (((CheckBox)ccitem).AutoPostBack)
                                {
                                    this._asyncLoadings.Remove(ccitem.ClientID);
                                }
                            }
                            else
                            {
                                this.RemoveNext(ccitem);
                            }
                        }
                    }
                }
            }
            else if (c is LinkButton || c is ImageButton || c is Button)
            {
                this._asyncLoadings.Remove(c.ClientID);
            }
            else if (c is DropDownList)
            {
                if (((DropDownList)c).AutoPostBack)
                {
                    this._asyncLoadings.Remove(c.ClientID);
                }
            }
            else if (c is CheckBox)
            {
                if (((CheckBox)c).AutoPostBack)
                {
                    this._asyncLoadings.Remove(c.ClientID);
                }
            }
            else
            {
                foreach (Control ccitem in c.Controls)
                {
                    if (ccitem is LinkButton || ccitem is ImageButton || ccitem is Button)
                    {
                        this._asyncLoadings.Remove(ccitem.ClientID);
                    }
                    else if (ccitem is DropDownList)
                    {
                        if (((DropDownList)ccitem).AutoPostBack)
                        {
                            this._asyncLoadings.Remove(ccitem.ClientID);
                        }
                    }
                    else if (ccitem is CheckBox)
                    {
                        if (((CheckBox)ccitem).AutoPostBack)
                        {
                            this._asyncLoadings.Remove(ccitem.ClientID);
                        }
                    }
                    else
                    {
                        this.RemoveNext(ccitem);
                    }
                }
            }
        }
        /// <summary>
        /// 获取页面的 GSC.WebControls.AsyncListLoadingWaitControl 控件对象。
        /// </summary>
        /// <remarks>获取页面的 GSC.WebControls.AsyncListLoadingWaitControl 控件对象。</remarks>
        /// <param name="page">设置当前页面对象。</param>
        /// <returns>GSC.WebControls.AsyncListLoadingWaitControl</returns>
        public static AsyncListLoadingWaitControl GetCurrent(Page page)
        {
            AsyncListLoadingWaitControl control = null;
            foreach (Control item in page.Controls)
            {
                if (item is HtmlForm)
                {
                    foreach (Control citem in item.Controls)
                    {
                        if (citem is AsyncListLoadingWaitControl)
                        {
                            control = (AsyncListLoadingWaitControl)citem;
                            break;
                        }
                    }
                }
            }
            if (control == null) throw new ArgumentNullException("没找到 AsyncListLoadingWaitControl 控件错误!");
            return control;
        }
        /// <summary>
        /// 获取页面的 GSC.WebControls.AsyncListLoadingWaitControl 控件对象。
        /// </summary>
        /// <remarks>获取页面的 GSC.WebControls.AsyncListLoadingWaitControl 控件对象。</remarks>
        /// <param name="master">设置当前页面模板对象。</param>
        /// <returns>GSC.WebControls.AsyncListLoadingWaitControl</returns>
        public static AsyncListLoadingWaitControl GetCurrent(MasterPage master)
        {
            AsyncListLoadingWaitControl control = null;
            foreach (Control item in master.Controls)
            {
                if (item is HtmlForm)
                {
                    foreach (Control citem in item.Controls)
                    {
                        if (citem is AsyncListLoadingWaitControl)
                        {
                            control = (AsyncListLoadingWaitControl)citem;
                            break;
                        }
                    }
                }
            }
            if (control == null) throw new ArgumentNullException("没找到 AsyncListLoadingWaitControl 控件错误!");
            return control;
        }
        /// <summary>
        /// 注册异步加载等待控件对象。
        /// </summary>
        /// <remarks>注册异步加载等待控件对象。</remarks>
        /// <param name="control">设置要注册的控件对象。</param>
        public void RegisterControl(Control control)
        {
            if (control == null) return;
            foreach (Control item in this._registerControlLists)
            {
                if (item.UniqueID.Equals(control.UniqueID, StringComparison.InvariantCultureIgnoreCase))
                {
                    return;
                }
            }
            if (!this._registerControlLists.Contains(control))
            {
                this._registerControlLists.Add(control);
            }
        }
        /// <summary>
        /// 注册异步加载等待控件对象。
        /// </summary>
        /// <remarks>注册异步加载等待控件对象。</remarks>
        /// <param name="control">设置要注册的控件客户端ID。</param>
        /// <returns>bool</returns>
        public bool RegisterControl(string control)
        {
            if (this._asyncLoadings.Contains(control))
            {
                return false;
            }
            this._asyncLoadings.Add(control);
            return true;
        }
        /// <summary>
        /// 注册异步加载等待控件事件。
        /// </summary>
        /// <remarks>注册异步加载等待控件事件。</remarks>
        /// <param name="e">事件对象。</param>
        protected virtual void OnRegister(EventArgs e)
        {
            EventHandler handler = (EventHandler)Events[_registerObject];
            if (handler != null)
            {
                handler(this, e);
            }
        }
        /// <summary>
        /// 
        /// </summary>
        class LoadingWaitControl : ScriptControl
        {
            #region 脚步资源
            /// <summary>
            /// 
            /// </summary>
            /// <returns></returns>
            protected override IEnumerable<ScriptDescriptor> GetScriptDescriptors()
            {
                //创建脚本描述。
                ScriptControlDescriptor descriptor = new ScriptControlDescriptor("GSC.WebControls.AsyncListLoadingWaitControl", this.ClientID);
                foreach (Control item in this._owner._registerControlLists)
                {
                    this._owner.AddNext(item);
                }
                this._owner.OnRegister(EventArgs.Empty);
                descriptor.AddProperty("AsyncIDs", this._owner._asyncLoadings);
                descriptor.AddProperty("Speed", this._owner.Speed);
                descriptor.AddProperty("Opacity", this._owner.Opacity);
                descriptor.AddProperty("Degenerating", this._owner.Degenerating);
                descriptor.AddProperty("Starts", this._owner.Starts);
                descriptor.AddProperty("FillWindowColor", this._owner.FillWindowColor.IsEmpty ? "#000000" : ColorTranslator.ToHtml(this._owner.FillWindowColor));
                descriptor.AddProperty("LoadingText", string.IsNullOrEmpty(this._owner.LoadingText) ? this._owner.GetString("LoadingText") : this._owner.LoadingText);
                descriptor.AddProperty("LoadingImage", string.IsNullOrEmpty(this._owner.LoadingImage) ? this.Page.ClientScript.GetWebResourceUrl(this._owner.GetType(), "GSC.WebControls.AsyncListLoadingWaitControl.Images.loading.gif") : this._owner.LoadingImage);
                yield return descriptor;
            }
            /// <summary>
            /// 生成脚本引用
            /// </summary>
            /// <returns></returns>
            protected override IEnumerable<ScriptReference> GetScriptReferences()
            {
                yield return new ScriptReference("GSC.WebControls.AsyncListLoadingWaitControl.AsyncListLoadingWaitControl.js", this.GetType().Assembly.FullName);
            }
            #endregion
            /// <summary>
            /// 
            /// </summary>
            AsyncListLoadingWaitControl _owner;
            /// <summary>
            /// 
            /// </summary>
            /// <param name="owner"></param>
            internal LoadingWaitControl(AsyncListLoadingWaitControl owner)
            {
                this._owner = owner;
            }
        }
    }
}